<?php

if (!function_exists('get_distance_sql')) {
    /**
     * @title 生成获取经纬度的sql
     * @return string
     * @author FashionJune
     */
    function get_distance_sql($lat, $lng, $start, $limit, $where='', $table='zz_shop_store')
    {
        return "SELECT s.*,s.lng,s.lat,"
        . "round((2 * 6378.137 * ASIN(SQRT(POW( SIN( PI()*( $lat- lat )/ 360 ), 2 )+ COS( PI()* $lat / 180 )* COS( lat * PI()/ 180 )* POW( SIN( PI()*( $lng- lng )/ 360 ), 2 )))) * 1000) AS distance"
        . " FROM `$table` s WHERE $where"
        . " ORDER BY distance ASC"
        . " LIMIT $start,$limit ;";
    }
}